package com.and.util.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.and.util.R;
import com.htg.util.UtilMatrix;

public class Matrix2DActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText etx,ety;
    private TextView tv;
    private Button bt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_matrix2_dactivity);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        etx = findViewById(R.id.etx);
        ety = findViewById(R.id.ety);
        tv = findViewById(R.id.tv);
        bt = findViewById(R.id.bt);

        bt.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt:

                String x = etx.getText().toString();
                String y = ety.getText().toString();

                if (x==null||y==null||x.trim().equals("")||y.trim().equals("")){
                    Toast.makeText(this,"请输入原坐标系坐标值",Toast.LENGTH_LONG).show();
                    return;
                }

                double sx1 = 1;
                double sy1 = 1;
                double sx2 = 2;
                double sy2 = 2;
                double sx3 = 1;
                double sy3 = 2;
                double mx1 = 1;
                double my1 = 0;
                double mx2 = 2;
                double my2 = 0;
                double mx3 = 1.5;
                double my3 = 0.5;
                double[] xy = UtilMatrix.getMatrix2D(sx1,sy1,sx2,sy2,sx3,sy3,mx1,my1,mx2,my2,mx3,my3).mapping(Double.parseDouble(x),Double.parseDouble(y));

                tv.setText("新坐标系里的坐标值为（"+String.valueOf(xy[0])+" , "+String.valueOf(xy[1])+"）");

            break;
        }
    }
}